home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / IAC Tools / iacsend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-09  |  3.2 KB  |  171 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4. #include "iacinternal.h"
  5.  
  6. #if __option (a4_globals)
  7.  
  8.     #include <SetupA4.h>
  9.  
  10. #endif
  11.  
  12.  
  13. /*
  14. 8/24/92 DW: This file includes routines that are likely to be used by code 
  15. that sends Apple Events.
  16. */
  17.  
  18. /*
  19. 6/6/93 JWB: Change #ifdef coderesource instances to #if __option (a4_globals)
  20. to make this automatic.
  21.             Change a4IACwaitroutine () to forward the value returned by
  22.             IACwaitroutine ()
  23. */
  24.  
  25.  
  26. Boolean IACnewverb (OSType receiver, OSType vclass, OSType vtoken, AppleEvent *event) {
  27.  
  28.     /*
  29.     create a new AppleEvent record addressed to the recipient, of the indicated class,
  30.     with the indicated token identifier. return true if it worked, false otherwise.
  31.     */
  32.     
  33.     AEAddressDesc adr; 
  34.     OSErr errcode;
  35.     
  36.     AECreateDesc (typeApplSignature, (Ptr) &receiver, sizeof (receiver), &adr);
  37.     
  38.     errcode = AECreateAppleEvent (
  39.         
  40.         vclass, vtoken, &adr, kAutoGenerateReturnID, kAnyTransactionID, event);
  41.     
  42.     AEDisposeDesc (&adr);
  43.     
  44.     IACglobals.errorcode = errcode;
  45.     
  46.     return (errcode == noErr);
  47.     } /*IACnewverb*/
  48.  
  49.  
  50. #if __option (a4_globals)
  51.  
  52. static pascal short a4IACwaitroutine (EventRecord *ev, long *sleep, RgnHandle *mousergn) {
  53.     
  54.     short result;
  55.     
  56.     SetUpA4 ();
  57.     
  58.     result = IACwaitroutine (ev, sleep, mousergn);
  59.     
  60.     RestoreA4 ();
  61.     
  62.     return (result);
  63.     } /*a4IACwaitroutine*/
  64.  
  65. #endif
  66.  
  67.  
  68. Boolean IACsendverb (AppleEvent *event, AppleEvent *reply) {
  69.  
  70.     /*
  71.     caller must dispose of the reply.
  72.     */
  73.  
  74.     register OSErr ec;
  75.     long mode;
  76.     
  77.     mode = kAEWaitReply + kAECanInteract + kAECanSwitchLayer;
  78.     
  79.     #if __option (a4_globals)
  80.     
  81.         RememberA4 ();
  82.         
  83.         ec = AESend (
  84.             
  85.             event, reply, mode, kAENormalPriority, kNoTimeOut, 
  86.             
  87.             (ProcPtr) a4IACwaitroutine, nil);
  88.         
  89.     #else
  90.     
  91.         ec = AESend (
  92.             
  93.             event, reply, mode, kAENormalPriority, kNoTimeOut, 
  94.             
  95.             (ProcPtr) IACwaitroutine, nil);
  96.         
  97.     #endif
  98.     
  99.     AEDisposeDesc (event);    
  100.     
  101.     IACglobals.errorcode = ec;
  102.     
  103.     return (ec == noErr);
  104.     } /*IACsendverb*/
  105.  
  106.  
  107. Boolean IACsendverbnoreply (AppleEvent *event, AppleEvent *reply) {
  108.  
  109.     OSErr ec;
  110.     long mode;
  111.  
  112.     mode = kAENoReply + kAENeverInteract;
  113.  
  114.     ec = AESend (event, reply, mode, kAEHighPriority, kNoTimeOut, nil, nil);
  115.  
  116.     AEDisposeDesc (event); 
  117.  
  118.     IACglobals.errorcode = ec;
  119.     
  120.     return (ec == noErr);
  121.     } /*IACsendverbnoreply*/
  122.  
  123.  
  124. Boolean IACiserrorreply (Str255 errorstring) {
  125.     
  126.     /*
  127.     return true if the reply is an error -- if so it has an 'errn' value
  128.     and an 'errs' value. if we return false, the reply is not an error.
  129.     */
  130.     
  131.     OSErr ec;
  132.     AEDesc desc;
  133.     
  134.     ec = AEGetParamDesc (IACglobals.reply, (AEKeyword) 'errn', 'shor', &desc);
  135.     
  136.     if (ec != noErr) /*the reply isn't an error*/
  137.         return (false);
  138.  
  139.     AEDisposeDesc (&desc);
  140.     
  141.     ec = AEGetParamDesc (IACglobals.reply, (AEKeyword) 'errs', 'TEXT', &desc);
  142.     
  143.     if (ec != noErr)
  144.         IACcopystring ("\pUnknown error.", errorstring);
  145.     else {
  146.         long lenstring = GetHandleSize (desc.dataHandle);
  147.         
  148.         if (lenstring > 255)
  149.             lenstring = 255;
  150.             
  151.         errorstring [0] = (char) lenstring;
  152.         
  153.         BlockMove (*desc.dataHandle, &errorstring [1], lenstring);
  154.         }
  155.     
  156.     AEDisposeDesc (&desc);
  157.     
  158.     return (true); /*there was an error returned*/
  159.     } /*IACiserrorreply*/
  160.  
  161.  
  162. Boolean IACdisposeverb (AppleEvent *event) {
  163.     
  164.     IACglobals.errorcode = AEDisposeDesc (event);
  165.  
  166.     return (IACglobals.errorcode == noErr);
  167.     } /*IACdisposeverb*/
  168.     
  169.     
  170.  
  171.